package com.google.android.apps.skipbot;

import android.os.AsyncTask;
import android.util.Log;

public class RobotMovementSequenceRunner extends AsyncTask<RobotMovementSequence, Integer, Boolean> {

  static final String TAG = "RobotMovementSequenceRunner";

  @Override
  protected Boolean doInBackground(RobotMovementSequence... sequences) {
    int count = sequences.length;
    for (int i = 0; i < count; i++) {
      if (isCancelled()) {
        return false;
      }
      RobotMovementSequence sequence = sequences[i];
      sequence.run(this);
    }
    return !this.isCancelled();
  }

  @Override
  protected void onCancelled() {
    super.onCancelled();
    Log.d(TAG, "Cancelled");
  }

  @Override
  protected void onProgressUpdate(Integer... values) {
    super.onProgressUpdate(values);
    Log.d(TAG, "Progress = " + values[0]);
  }

  @Override
  protected void onPostExecute(Boolean result) {
    super.onPostExecute(result);
    Log.d(TAG, result ? "Completed successfully" : "Completed unsuccessfully");
  }
}
